package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * User: 章华隽
 * E-mail: nefeed@163.com
 * Desc:
 * Date: 2017-08-09
 * Time: 11:03
 */
public enum TagTypeEnum {
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), "enum.tagType.name.contract", "contract"),

    CUSTOMER(XbbRefTypeEnum.CUSTOMER.getCode(), "enum.tagType.name.customer", "customer"),

    PUBLIC_CUSTOMER_RULE(XbbRefTypeEnum.CUSTOMER_PUBLIC.getCode(), "enum.tagType.name.public_customer_rule", "publicCustomerRule"),

    PUBLIC_CLUE_RULE(XbbRefTypeEnum.CLUE_PUBLIC.getCode(), "enum.tagType.name.public_clue_rule", "publicClueRule"),

    TRANSFER_CUSTOMER_RULE(XbbRefTypeEnum.CUSTOMER_TRANSFER.getCode(),"enum.tagType.name.transfer_customer_rule","transferCustomerRule"),

    TRANSFER_CLUE_RULE(XbbRefTypeEnum.CLUE_TRANSFER.getCode(),"enum.tagType.name.transfer_clue_rule","transferClueRule"),

    CONTACT(XbbRefTypeEnum.CONTACT.getCode(), "enum.tagType.name.contact", "contact"),

    APPROVAL(XbbRefTypeEnum.APPROVAL.getCode(), "enum.tagType.name.approval", "approval"),

    SALES_OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), "enum.tagType.name.sales_opportunity", "salesOpportunity"),

    CUSTOMER_COMMUNICATE(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), "enum.tagType.name.customer_communicate", "customerCommunicate"),

    PRODUCT(XbbRefTypeEnum.PRODUCT.getCode(), "enum.tagType.name.product", "product"),

    COMMUNICATE_PLAN(XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), "enum.tagType.name.communicate_plan", "communicatePlan"),

    WORK_REPORT(XbbRefTypeEnum.WORK_REPORT.getCode(), "enum.tagType.name.work_report", "workReport"),

    INVOICE(XbbRefTypeEnum.INVOICE.getCode(), "enum.tagType.name.invoice", "invoice"),

    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), "enum.tagType.name.purchase", "purchase"),

    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), "enum.tagType.name.returned_purchase", "returnedPurchase"),

    SYSTEM(XbbRefTypeEnum.SYSTEM.getCode(), "enum.tagType.name.system", "systemNotification"),

    UNKNOWN(XbbRefTypeEnum.UNKNOWN.getCode(), "enum.tagType.name.unknown", "unknown"),
    
    ARCHIVED(1001, "enum.tagType.name.archived", "archived"),
    ;


    /** 枚举值 -- */
    private final int		code;

    /** 枚举信息--中文名称 */
    private final String name;

    /** 枚举描述 --英文名称*/
    private final String alias;

    /**
     * 构造一个枚举对象
     *
     * @param code 枚举值
     * @param name 枚举类型名
     * @param alias 枚举类型英文别名
     */
    TagTypeEnum(int code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * @return Returns the code.
     */
    public int getCode() {
        return code;
    }

    /**
     * @return Returns the name.
     */
    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * @return Returns the alias.
     */
    public String getAlias() {
        return alias;
    }

    /**
     * 通过枚举 alias 获得枚举
     *
     * @param alias 枚举别名
     *
     * @return TagTypeEnum
     */
    public static TagTypeEnum getByAlias(String alias) {
        for (TagTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return TagTypeEnum
     */
    public static TagTypeEnum getByCode(Integer code) {
        for (TagTypeEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<TagTypeEnum>
     */
    public List<TagTypeEnum> getAllEnum() {
        List<TagTypeEnum> list = new ArrayList<>();
        for (TagTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (TagTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }
}
